<%-- 
    Document   : serviceEnseignantForm
    Created on : 23 mai 2014, 09:35:15
    Author     : Christophe
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<script lang="text/javascript">
    
    $("#structures").change(onStructureChange);
    
    function onStructureChange(){
        
        var structureId = $("#structures").val();
        
        $.ajax({
           url : "eleves.list.structure",
           data:  {
               "structureid" : structureId
           },
           success: function (data) {
               printListeEleves(data, $("#listeEleves"));
           },
           error: function (jqXHR, textStatus, errorThrown) {
               alert("ERREUR: Impossible de contacter le serveur");
           }
        });
    }
    
    function printListeEleves(eleves, target){
        
        var html = "";
        
        if(eleves.length == 0){
            html = "Aucun élève enregistré dans ce groupe ou cette classe."
        }
        
        for(var i = 0; i < eleves.length; i++){
            
            html += "<tr>";
            html += "   <td>" + eleves[i].nom + " " + eleves[i].prenom + "</td>";
            html += "</tr>";
        }
        
        $(target).html(html);
    }
</script>

<div class="container-fluid">
    <div class="row">
        <form:form name="frmServiceEnseignant" action="service.enseignant.save" method="post" modelAttribute="service" cssClass="form-horizontal">
            
            <form:hidden path="enseignant.id" />
            
            <div class="form-group">
                <label class="col-sm-2 control-label" for="matieres">Matiere</label>
                 <div class="col-sm-10">
                     <form:select id="matieres" items="${matieres}" itemValue="id" itemLabel="libelleLong" path="matiere">
                     </form:select>
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-2 control-label" for="structures">Groupe/Classe</label>
                 <div class="col-sm-10">
                     <form:select id="structures" items="${structures}" itemValue="id" itemLabel="libelle" path="groupe">
                     </form:select>
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-2 control-label" for="heures">Nbre heures</label>
                <div class="col-sm-10">
                    <form:input id="heure" path="nbrHeures" />
                </div>
            </div>
            
        </form:form>
    </div>
    <div class="row">
        <table class="table">
            <thead>
                <tr>
                    <th>Nom Prénom</th>
                </tr>
            </thead>
            <tbody id="listeEleves">
            </tbody>
        </table>
    </div>
</div>